package cn.tedu.cgb2202.sk.admin.webapi.controller;

import cn.tedu.cgb2202.sk.admin.service.IAdminService;
import cn.tedu.cgb2202.sk.common.web.JsonResult;
import cn.tedu.cgb2202.sk.pojo.dto.AdminAddNewDTO;
import cn.tedu.cgb2202.sk.pojo.dto.AdminLoginDTO;
import cn.tedu.cgb2202.sk.pojo.vo.AdminSimpleVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 2022.6.14
 * 胡然
 * 用户登录注册模块控制器层
 */
@RestController
@RequestMapping(value = "/admins",produces = "application/json;charset=utf-8")
public class AdminController {

    @Autowired
    private IAdminService adminService;

    /**
     * 2022.6.14
     * 胡然
     * 用户注册
     * @param adminAddNewDTO 用户填写的信息
     * @return Json数据
     */
    @PostMapping("/reg")
    public JsonResult<Void> addNew(@RequestBody AdminAddNewDTO adminAddNewDTO){
        adminService.addNew(adminAddNewDTO);
        return JsonResult.ok();
    }

    /**
     * 2022.6.15
     * 胡然
     * 用户登录
     * @param adminLoginDTO 用户提交的数据
     * @return 返回用户信息
     */
    @PostMapping("/login")
    public JsonResult<AdminSimpleVO> login(@RequestBody AdminLoginDTO adminLoginDTO){
        AdminSimpleVO admin = adminService.login(adminLoginDTO);
        return JsonResult.ok(admin);
    }
}
